<?php 
 include_once dirname(__FILE__)."/config.php";
 class resource_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_id_resource;
		 protected $_lib_resource;
		 public function get_name_table(){ return "resource";}
		 public function get_name_id_resource(){ return "id_resource";}
		 public function get_name_lib_resource(){ return "lib_resource";}
		 public function set_id_resource($parametre){  $this->_id_resource=$parametre;}	
		 public function set_lib_resource($parametre){  $this->_lib_resource=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_id_resource(){ return $this->_id_resource;}
		 public function get_lib_resource(){ return $this->_lib_resource;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 resource(
			lib_resource)
 VALUES(
			'".$this->_lib_resource."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_lib_resource)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
lib_resource='".$this->_lib_resource."'";
}
$sql="UPDATE 
resource SET 
 ".$sql."
								WHERE id_resource ='".$this->_id_resource."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
resource 
 
									WHERE id_resource ='".$this->_id_resource."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
resource ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		id_resource,
		lib_resource
 FROM 
 resource";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_id_resource=$row->id_resource;
		$this->_lib_resource=$row->lib_resource;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>